package com.atguigu.lease.web.admin.custom.config;

import com.atguigu.lease.web.admin.custom.converter.StringToBaseEnumConverterFacotry;
import com.atguigu.lease.web.admin.custom.converter.StringToItemTypeConverter;
import com.atguigu.lease.web.admin.custom.interceptor.AuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//注册converter和拦截器
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
    @Autowired
    private StringToBaseEnumConverterFacotry stringToBaseEnumConverterFacotry;
    @Autowired
    private AuthenticationInterceptor authenticationInterceptor;
  /*  @Autowired
    private StringToItemTypeConverter stringToItemTypeConverter;*/
    @Override
    public void addFormatters(FormatterRegistry registry) {
        /*registry.addConverter(this.stringToItemTypeConverter);*/
        registry.addConverterFactory(this.stringToBaseEnumConverterFacotry);
        //registry注册
    }
    //注册拦截器
    public void addInterceptors(InterceptorRegistry registry)
    {
        registry.addInterceptor(this.authenticationInterceptor)//注册拦截器
                .addPathPatterns("/admin/**")//设置拦截的内容
                .excludePathPatterns("/admin/login/**");//设置不拦截的内容
    }
}
